package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Sales;
import com.ruoyi.system.service.ISalesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 发售Controller
 * 
 * @author ruoyi
 * @date 2024-07-04
 */
@RestController
@RequestMapping("/system/sales")
public class SalesController extends BaseController
{
    @Autowired
    private ISalesService salesService;

    /**
     * 查询发售列表
     */
    @PreAuthorize("@ss.hasPermi('system:sales:list')")
    @GetMapping("/list")
    public TableDataInfo list(Sales sales)
    {
        startPage();
        List<Sales> list = salesService.selectSalesList(sales);
        return getDataTable(list);
    }

    /**
     * 导出发售列表
     */
    @PreAuthorize("@ss.hasPermi('system:sales:export')")
    @Log(title = "发售", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Sales sales)
    {
        List<Sales> list = salesService.selectSalesList(sales);
        ExcelUtil<Sales> util = new ExcelUtil<Sales>(Sales.class);
        util.exportExcel(response, list, "发售数据");
    }

    /**
     * 获取发售详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:sales:query')")
    @GetMapping(value = "/{salesId}")
    public AjaxResult getInfo(@PathVariable("salesId") Long salesId)
    {
        return success(salesService.selectSalesBySalesId(salesId));
    }

    /**
     * 新增发售
     */
    @PreAuthorize("@ss.hasPermi('system:sales:add')")
    @Log(title = "发售", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Sales sales)
    {
        return toAjax(salesService.insertSales(sales));
    }

    /**
     * 修改发售
     */
    @PreAuthorize("@ss.hasPermi('system:sales:edit')")
    @Log(title = "发售", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Sales sales)
    {
        return toAjax(salesService.updateSales(sales));
    }

    /**
     * 删除发售
     */
    @PreAuthorize("@ss.hasPermi('system:sales:remove')")
    @Log(title = "发售", businessType = BusinessType.DELETE)
	@DeleteMapping("/{salesIds}")
    public AjaxResult remove(@PathVariable Long[] salesIds)
    {
        return toAjax(salesService.deleteSalesBySalesIds(salesIds));
    }
}
